package com.sixth.service.Impl;

import com.sixth.dao.AuditDao;
import com.sixth.entity.*;
import com.sixth.service.AuditService;
import com.sixth.util.CommonResult;
import com.sixth.util.LayTab;
import com.sixth.util.TableLayUi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @program: project01
 * @description:
 * @author: 老魏
 * @create: 2021-12-18 16:30
 **/
@Service("/auditService")
public class AuditServiceImpl implements AuditService {
    @Autowired
    public AuditDao auditDao;
    @Autowired
    public HttpSession session;

    public AuditServiceImpl(){

    }

    public CommonResult updateStatus(Integer id, Integer status, Date dates) {
        Warehousing warehousing1 = new Warehousing();
        new Warehousings();
        Staff staff = (Staff)this.session.getAttribute("staff");
        warehousing1.setDates(new Date());
        int i = this.auditDao.updateStatus(id, status, new Date());
        CommonResult CommonResult = null;
        if (i > 0) {
            List<Warehousings> warehousingDetails = this.auditDao.getWarehousingDetails(id);
            Warehousing warehousing = new Warehousing();
            warehousing.setBranchid(staff.getBranchid());
            Iterator var11 = warehousingDetails.iterator();

            while(var11.hasNext()) {
                Warehousings warehousingDetail = (Warehousings)var11.next();
                Integer goodsid = warehousingDetail.getGoodsid();
                Integer num = warehousingDetail.getNum();
                this.auditDao.batchOutLibrary(warehousing.getBranchid(), goodsid, num);
            }

            CommonResult = CommonResult.success((Object)null, "操作成功");
        } else {
            CommonResult = CommonResult.fail("操作失败");
        }

        return CommonResult;
    }
    //
    public CommonResult updateStatuses(Integer id, Integer status, Date dates, String msg) {
        int i = this.auditDao.updateStatuses(id, status, new Date(), msg);
        CommonResult CommonResult = null;
        if (i > 0) {
            CommonResult = CommonResult.success((Object)null, "操作成功");
        } else {
            CommonResult = CommonResult.fail("操作失败");
        }

        return CommonResult;
    }

    public CommonResult update(Integer id, Integer status) {
        int i = this.auditDao.update(id, status);
        CommonResult CommonResult = null;
        if (i > 0) {
            CommonResult = CommonResult.success((Object)null, "操作成功");
        } else {
            CommonResult = CommonResult.fail("操作失败");
        }

        return CommonResult;
    }

    public LayTab getAllWarehousings(Staff staff, Warehousings warehousings, Integer id) {
        List<Map> allWarehousings = this.auditDao.getAllWarehousings(staff, warehousings, id);
        LayTab TableLayUi = new LayTab(allWarehousings.size(), allWarehousings);
        return TableLayUi;
    }

    public LayTab getAllShoping(Goods goods, Limit limit) {
        List<Goods> allShoping = this.auditDao.getAllShoping(goods, limit);
        LayTab TableLayUi = new LayTab(allShoping.size(), allShoping);
        return TableLayUi;
    }
}
